package mark.tom.friend.app;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.github.yuweiguocn.library.greendao.MigrationHelper;
import mark.tom.friend.bean.db.AppConfigDODao;
import mark.tom.friend.bean.db.AppInfoDODao;
import mark.tom.friend.bean.db.ConfigRecordDODao;
import mark.tom.friend.bean.db.DaoMaster;
import org.greenrobot.greendao.database.Database;

public class CustomDBHelper extends DaoMaster.OpenHelper {

    public CustomDBHelper(Context context, String name) {
        super(context, name);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        //noinspection unchecked
        MigrationHelper.migrate(db, new MigrationHelper.ReCreateAllTableListener() {
            @Override
            public void onCreateAllTables(Database db, boolean ifNotExists) {
                DaoMaster.createAllTables(db, ifNotExists);
            }

            @Override
            public void onDropAllTables(Database db, boolean ifExists) {
                DaoMaster.dropAllTables(db, ifExists);
            }
        }, AppInfoDODao.class, AppConfigDODao.class, ConfigRecordDODao.class);
    }
}
